// UeObjectId.h: interface for the UeObjectId class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_UEOBJECTID_H__4CBDD229_8349_4BB0_A51D_CC60164D7D56__INCLUDED_)
#define AFX_UEOBJECTID_H__4CBDD229_8349_4BB0_A51D_CC60164D7D56__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxtempl.h>

enum ElementType
{
	EquipType  = 0,
	NozzleType = 1,
	TubeType   = 2,
	StructureType =3
};

class DllExport ObjectId 
{
public:
	ObjectId(){
		m_lObjectId = 0;
		m_lEnv = 0;
	}
	ObjectId( unsigned long lEnv, unsigned long lId ){
		m_lObjectId = lId;
		m_lEnv = lEnv;
	}

	ObjectId( const StdString& strID ){
		int nPos = strID.Find( '\\' );
		m_lEnv = atol( strID.Left( nPos ) );
		m_lObjectId = atol( strID.Right( strID.GetLength() - nPos -1 ) );
	}
	ObjectId(const ObjectId& id){
		m_lObjectId = id.m_lObjectId;
		m_lEnv = id.m_lEnv;
	}

	virtual ~ObjectId(){}

public:
	BOOL IsNull() const {
		return m_lObjectId == 0 || m_lEnv == 0;
	}

	const ObjectId& operator=(const ObjectId& other){
		if(this == &other)
			return *this;
		m_lObjectId = other.m_lObjectId;
		m_lEnv = other.m_lEnv;
		return *this;
	}

	BOOL operator==(const ObjectId& id) const {
		return m_lObjectId == id.m_lObjectId && m_lEnv == id.m_lEnv;
	}

	BOOL operator!=(const ObjectId& id) const {
		return m_lObjectId != id.m_lObjectId || m_lEnv != id.m_lEnv;
	}

	UINT HashCode() const {
		return (UINT)(m_lEnv << 16 | m_lObjectId);
	}

	StdString ToString() const {
		StdString strTemp;
		strTemp.Format( _T("%ld\\%ld"), m_lEnv, m_lObjectId );
		return strTemp;
	}

	unsigned long EnviromentID() const {
		return m_lEnv;
	}

	unsigned long ObjectID() const {
		return m_lObjectId;
	}
private:
	unsigned long m_lEnv;
	unsigned long m_lObjectId;
};

typedef ObjectId UeObjectId;
typedef CArray<ObjectId, ObjectId> UeObjectIdSet;

AFX_INLINE UINT AFXAPI HashKey(UeObjectId key)
{
	return key.HashCode();
}

INLINE void InitVariable(UeObjectId& var)
{
}

class IDGenerator
{
public:
	IDGenerator( unsigned long lEnv, unsigned long lStartID ) {
		m_lEnv = lEnv;
		m_lStartID = lStartID;
	}
	~IDGenerator(){}

public:
	UeObjectId Generate() {
		m_lStartID++;
		return UeObjectId(m_lEnv, m_lStartID );
	}

	unsigned long CurCount() const {
		return m_lStartID;
	}

private:
	unsigned long m_lEnv;
	unsigned long m_lStartID;
};
/*
SmallObject* GetObject(const UeObjectId& Id);
template<typename Output> Output* ConvertObjectId(Output* o, const UeObjectId& id)
{
	SmallObject* pObj = GetObject(id);
	if(pObj == NULL)
	{
		ASSERT(pObj);
		return NULL;
	}

	if(pObj->IsKindOf(UE_RUNTIME_CLASS(Output)))
		return (Output*)pObj;

	return NULL;
}
*/

#endif // !defined(AFX_UEOBJECTID_H__4CBDD229_8349_4BB0_A51D_CC60164D7D56__INCLUDED_)
